package com.hrhx.duhongming.web;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.abel533.echarts.json.GsonOption;
import com.hrhx.duhongming.bean.EchartsConfig;
import com.hrhx.duhongming.core.HighChartsCore;
import com.hrhx.duhongming.utils.JsonUtil;

@Controller
@RequestMapping(value="/highcharts")
public class HighChartsDemo {
	
	/**
	 * 演示页面
	 * @return
	 */
	@RequestMapping(value="demo")
	public String echartsDemo(){
		return "/highcharts/demo";
	}
	
	/**
	 * 3D条形图
	 * @param echartsConfig
	 * @return
	 */
	@RequestMapping(value="bar3d")
	public @ResponseBody String bar3d(@RequestBody EchartsConfig echartsConfig){
		//配置
		HighChartsCore highChartsCore = HighChartsCore.getInstance();
		GsonOption gsonOption = highChartsCore.getBaseGsonOption(echartsConfig);
		gsonOption = highChartsCore.adapterBar3D(echartsConfig, gsonOption, getBarData());
		System.out.println("测试传入参数："+echartsConfig.getParameters());
		return gsonOption.toString();
	}
	
	/**
	 * 3D饼状图
	 * @param echartsConfig
	 * @return
	 */
	@RequestMapping(value="pie3d")
	public @ResponseBody String pie3d(@RequestBody EchartsConfig echartsConfig){
		//配置
		HighChartsCore highChartsCore = HighChartsCore.getInstance();
		GsonOption gsonOption = highChartsCore.getBaseGsonOption(echartsConfig);
		gsonOption = highChartsCore.adapterPie3D(echartsConfig, gsonOption, getPieData());
		return gsonOption.toString();
	}
	
	//测试数据请忽略
	private List<Map<String,Object>> getBarData(){
		//相当于二维数据表数据
		//x代表X轴的数据
		//y0代表Y轴左面的数据
		//x:日期           y0:最高气温          y0:最低气温
		//周一                11          11
		String jsonData="[{\"y0:最高气温\":11,\"y0:最低气温\":1,\"x:日期\":\"周一\"},{\"y0:最高气温\":11,\"y0:最低气温\":-2,\"x:日期\":\"周二\"},{\"y0:最高气温\":15,\"y0:最低气温\":2,\"x:日期\":\"周三\"},{\"y0:最高气温\":13,\"y0:最低气温\":5,\"x:日期\":\"周四\"},{\"y0:最高气温\":12,\"y0:最低气温\":3,\"x:日期\":\"周五\"},{\"y0:最高气温\":13,\"y0:最低气温\":2,\"x:日期\":\"周六\"},{\"y0:最高气温\":10,\"y0:最低气温\":1,\"x:日期\":\"周日\"}]";
			return new JsonUtil().getMapListData(jsonData);
	}
	
	//测试数据请忽略
	private Map<String,Object> getPieData(){
		String jsonData="{\"搜索引擎\":1548,\"视频广告\":135,\"联盟广告\":234,\"邮件营销\":310,\"直接访问\":310}";
		return new JsonUtil().getMapData(jsonData);
	}
}
